<?php 
$appid='101353491';			// APPID
$appkey='df4e46ba7da52f787c6e3336d30526e4';			// APPKEY
$redirect_uri='http://www.iwebshop.com/index.php';		// 回调地址
$state = rand(1000,9999);
if ($_GET['code']) {
	$code = $_GET['code'];
	$url = "https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=$appid&client_secret=$appkey&code=$code&redirect_uri=$redirect_uri";
	$data = file_get_contents($url);
	$start = strpos($data, "=");
	$end = strpos($data, "&");
	$access_token = substr($data, $start+1 ,$end-$start-1);
	$url = "https://graph.qq.com/oauth2.0/me?access_token=$access_token";
	$data = file_get_contents($url);
	$start = strpos($data, "(");
	$end = strpos($data, ")");
	$data = substr($data, $start+1 ,$end-$start-1);
	$data = json_decode($data,true);
	$openid = $data['openid'];
	// print_r($openid);
	$url = "https://graph.qq.com/user/get_user_info?access_token=$access_token&oauth_consumer_key=$appid&openid=$openid";
	$data = file_get_contents($url);
	$data = json_decode($data,true);
	$img = $data['figureurl_qq_2'];
	echo "欢迎你".$data['nickname']."登录";
	echo "<img src='$img'>";
	// print_r($access_token);
	die();
}
$url = "https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=$appid&redirect_uri=$redirect_uri&state=$state";
header("Location:$url");


 ?>